package natappvip.liujinliang.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import natappvip.liujinliang.util.PropertiesUtil;

/**
 * @ClassName:  DeleteServlet   
 * @Despt: 文件删除服务端处理程序   
 * @Auth: Liujinliang 
 * @Date: 2018年7月29日 下午9:43:29
 */
public class DeleteServlet extends BaseControllerServlet {

	/**   
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)   
	 */ 
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		
		request.setCharacterEncoding(PropertiesUtil.getProperty("charset"));
		response.setCharacterEncoding(PropertiesUtil.getProperty("charset"));
		
		String uuid = request.getParameter("uuid");
		
		int res = fileSourceService.delete(uuid);
		fileMetaDataLocalService.remove(uuid);
		
		response.setContentType("text/html");
		response.setStatus(HttpServletResponse.SC_OK);
		
		if (res == 0) {
			response.getWriter().println("<h1>文件：" + uuid + "删除成功</h1>");
		} else {
			response.getWriter().println("<h1>文件：" + uuid + "删除失败</h1>");
		}
		
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		doGet(request, response);
	}
}
